﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:controls="clr-namespace:FirstFloor.ModernUI.Windows.Controls">

    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="/FirstFloor.ModernUI;component/Assets/Calendar.xaml" />
    </ResourceDictionary.MergedDictionaries>

    <Style TargetType="{x:Type DatePicker}">
        <Setter Property="Background" Value="{DynamicResource InputBackground}" />
        <Setter Property="Foreground" Value="{DynamicResource InputText}" />
        <Setter Property="BorderBrush" Value="{DynamicResource InputBorder}" />
        <Setter Property="BorderThickness" Value="1" />
        <Setter Property="IsTodayHighlighted" Value="True" />
        <Setter Property="SelectedDateFormat" Value="Short" />
        <Setter Property="Padding" Value="2,2,2,1"/>
        <Setter Property="HorizontalContentAlignment" Value="Stretch" />
        <Setter Property="Focusable" Value="True" />

        <Setter Property="CalendarStyle">
            <Setter.Value>
                <Style TargetType="Calendar" BasedOn="{StaticResource {x:Type Calendar}}">
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="Calendar">
                                <Grid Name="PART_Root" Margin="4" HorizontalAlignment="Center">
                                    <Border Background="#0C000000" BorderBrush="#0F000000" BorderThickness="1" CornerRadius="2.5" Margin="-1" />
                                    <Border Background="#0A000000" BorderBrush="#0C000000" BorderThickness="1" CornerRadius="2.75" Margin="-2" />

                                    <CalendarItem Name="PART_CalendarItem" 
                                                  Background="{DynamicResource PopupBackground}"
                                                  Style="{TemplateBinding CalendarItemStyle}"
                                                  BorderThickness="0"
                                                  Margin="1"/>

                                    <Border BorderBrush="{DynamicResource Accent}" BorderThickness="1" />
                                </Grid>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
            </Setter.Value>
        </Setter>

        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type DatePicker}">
                    <Border x:Name="LayoutRoot" BorderBrush="{TemplateBinding BorderBrush}" 
                            BorderThickness="{TemplateBinding BorderThickness}"
                            Background="{TemplateBinding Background}" 
                            Padding="{TemplateBinding Padding}">
                        <Grid x:Name="PART_Root"
                              HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" 
                              VerticalAlignment="{TemplateBinding VerticalContentAlignment}">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*" />
                                <ColumnDefinition Width="Auto" />
                            </Grid.ColumnDefinitions>
                            <controls:ModernButton x:Name="PART_Button" Grid.Row="0" Grid.Column="1"
                                                   Width="20"
                                                   Margin="3,0,3,0" 
                                                   Padding="0"
                                                   Focusable="False" 
                                                   VerticalAlignment="Top"
                                                   HorizontalAlignment="Left"
                                                   EllipseStrokeThickness="0"
                                                   IconWidth="12" IconHeight="12"
                                                   IconData="F1 M 34.0047,52.0073L 31.0042,52.0073L 31.0042,38.5053C 29.6649,39.8964 28.157,40.7849 26.3412,41.4502L 26.3412,37.7553C 27.2998,37.4474 28.3405,36.8645 29.4634,36.0068C 30.5862,35.149 31.3572,34.1483 31.7762,33.0046L 34.0047,33.0046L 34.0047,52.0073 Z M 45.0063,52.0073L 45.0063,48.0067L 37.0052,48.0067L 37.0052,45.0063L 45.0063,33.0046L 48.0067,33.0046L 48.0067,45.0063L 50.007,45.0063L 50.007,48.0067L 48.0067,48.0067L 48.0067,52.0073L 45.0063,52.0073 Z M 45.0063,45.0063L 45.0063,38.2555L 40.2556,45.0063L 45.0063,45.0063 Z M 18.0025,57.0082L 18.0025,23.0033L 23.0032,23.0033L 23.0032,20.0029C 23.0033,18.898 23.8988,18.0026 25.0035,18.0026L 29.004,18.0026C 30.1087,18.0026 31.0042,18.898 31.0043,20.0026L 31.0043,23.0033L 45.0063,23.0033L 45.0062,20.0026C 45.0062,18.8979 45.9018,18.0023 47.0065,18.0023L 51.0071,18.0023C 52.1118,18.0023 53.0074,18.8979 53.0074,20.0026L 53.0074,23.0033L 58.0081,23.0033L 58.0081,57.0082L 18.0025,57.0082 Z M 21.0029,54.0078L 55.0076,54.0078L 55.0076,31.0044L 21.0029,31.0044L 21.0029,54.0078 Z M 48.5067,20.0029C 47.6782,20.0029 47.0065,20.6746 47.0065,21.5031L 47.0065,24.5035C 47.0065,25.3321 47.6782,26.0038 48.5067,26.0038L 49.5068,26.0038C 50.3354,26.0038 51.007,25.3321 51.007,24.5035L 51.007,21.5031C 51.007,20.6746 50.3354,20.0029 49.5068,20.0029L 48.5067,20.0029 Z M 26.5037,20.0029C 25.6751,20.0029 25.0035,20.6745 25.0035,21.5031L 25.0035,24.5035C 25.0035,25.3321 25.6751,26.0037 26.5037,26.0037L 27.5038,26.0037C 28.3324,26.0037 29.004,25.3321 29.004,24.5035L 29.004,21.5031C 29.004,20.6745 28.3324,20.0029 27.5038,20.0029L 26.5037,20.0029 Z"/>

                            <DatePickerTextBox x:Name="PART_TextBox" 
                                               Foreground="{TemplateBinding Foreground}" 
                                               HorizontalContentAlignment="Stretch"
                                               VerticalContentAlignment="Center"
                                               Focusable="{TemplateBinding Focusable}" />
                            <Popup x:Name="PART_Popup" 
                                   PlacementTarget="{Binding ElementName=LayoutRoot}"
                                   Placement="Bottom" 
                                   HorizontalOffset="-4"
                                   VerticalOffset="-5"
                                   StaysOpen="False"
                                   AllowsTransparency="True" />
                        </Grid>
                    </Border>

                    <ControlTemplate.Triggers>
                        <Trigger Property="IsEnabled" Value="false">
                            <Setter TargetName="PART_TextBox" Property="Foreground" Value="{DynamicResource InputTextDisabled}" />
                        </Trigger>
                        <Trigger Property="IsFocused" Value="true">
                            <Setter TargetName="LayoutRoot" Property="BorderBrush" Value="{DynamicResource Accent}" />
                        </Trigger>
                        <Trigger Property="IsKeyboardFocusWithin" Value="true">
                            <Setter TargetName="LayoutRoot" Property="BorderBrush" Value="{DynamicResource Accent}" />
                        </Trigger>
                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition Property="IsEnabled" Value="True"/>
                                <Condition Property="IsMouseOver" Value="True"/>
                            </MultiTrigger.Conditions>
                            <Setter Property="Background" Value="{DynamicResource InputBackgroundHover}"/>
                            <Setter Property="BorderBrush" Value="{DynamicResource InputBorderHover}"/>
                            <Setter Property="Foreground" Value="{DynamicResource InputTextHover}"/>
                        </MultiTrigger>
                    </ControlTemplate.Triggers>

                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style TargetType="{x:Type DatePickerTextBox}">
        <Setter Property="Foreground" Value="{DynamicResource InputText}"/>
        <Setter Property="Background" Value="Transparent"/>
        <Setter Property="BorderThickness" Value="0" />
        <Setter Property="Padding" Value="1,0,0,0" />
        <Setter Property="ScrollViewer.PanningMode" Value="VerticalFirst"/>
        <Setter Property="Stylus.IsFlicksEnabled" Value="False"/>
        <Setter Property="FocusVisualStyle" Value="{x:Null}" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="DatePickerTextBox">
                    <Grid>
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup Name="WatermarkStates">
                                <VisualStateGroup.Transitions>
                                    <VisualTransition GeneratedDuration="0" />
                                </VisualStateGroup.Transitions>
                                <VisualState Name="Unwatermarked" />
                                <VisualState Name="Watermarked">
                                    <Storyboard>
                                        <DoubleAnimation Storyboard.TargetName="ContentElement" Storyboard.TargetProperty="Opacity" To="0" Duration="0" />
                                        <DoubleAnimation Storyboard.TargetName="PART_Watermark" Storyboard.TargetProperty="Opacity" To="1" Duration="0" />
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>

                        <Border x:Name="Border" 
                                Background="{TemplateBinding Background}" 
                                BorderBrush="{TemplateBinding BorderBrush}" 
                                BorderThickness="{TemplateBinding BorderThickness}"
                                Padding="{TemplateBinding Padding}">
                            <Grid x:Name="WatermarkContent"
                                  HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                  VerticalAlignment="{TemplateBinding VerticalContentAlignment}">
                                <Border x:Name="ContentElement" BorderThickness="0" Opacity="1" />
                                <Border x:Name="watermark_decorator" BorderThickness="0">
                                    <ContentControl x:Name="PART_Watermark"
                                                    Opacity="0"
                                                    Focusable="False"
                                                    IsHitTestVisible="False"
                                                    Margin="3,0"/>
                                </Border>
                                <ScrollViewer x:Name="PART_ContentHost" 
                                              Margin="0"
                                              HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
                                              VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}" />
                            </Grid>
                        </Border>
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsEnabled" Value="false">
                            <Setter TargetName="PART_Watermark" Property="Foreground" Value="{DynamicResource InputTextDisabled}"/>
                        </Trigger>
                        <Trigger Property="IsReadOnly" Value="true">
                            <Setter TargetName="PART_Watermark" Property="Foreground" Value="{DynamicResource InputTextDisabled}"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                    
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

</ResourceDictionary>